package com.bc.ljn.catwars;

import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Paint;

/**
 * Created by ljn on 2014/12/26.
 */
public class Score {
    //加载分数图片
    private Bitmap bmpScore;
    //当前帧下标
    private int scoreIndex;
    public int frameW, framwH;
    //总分
    public static int totleScore = 0;
    int score[] = {0, 0, 0, 0, 0};

    public Score(Bitmap bitmap) {
        bmpScore = bitmap;
        frameW = bmpScore.getWidth() / 10;
        framwH = bmpScore.getHeight();
        totleScore = 9191;
    }

    public void draw(Canvas canvas, Paint paint) {
        for (int i = 0; i < 5; i++) {
            canvas.save();
            canvas.clipRect(GameView.screenW - frameW * (i + 1), 5,
                    GameView.screenW - frameW * i, 5 + framwH);
            canvas.drawBitmap(bmpScore,
                    GameView.screenW - bmpScore.getWidth() + frameW * (1 - score[4 - i] - i), 5, paint);
            canvas.restore();
        }
//
//        //画个位数
//        canvas.save();
//        canvas.clipRect(GameView.screenW - frameW, 5, GameView.screenW, 5 + framwH);
//        canvas.drawBitmap(bmpScore, (_0 - 1) * frameW, 5, paint);
//        canvas.restore();
//        //画十位数
//        canvas.save();
//        canvas.clipRect(GameView.screenW - frameW * 2, 5, GameView.screenW - frameW, 5 + framwH);
//        canvas.drawBitmap(bmpScore, (_10 - 2) * frameW, 5, paint);
//        canvas.restore();
//        //画百位数
//        canvas.save();
//        canvas.clipRect(GameView.screenW - frameW * 3, 5, GameView.screenW - frameW * 2, 5 + framwH);
//        canvas.drawBitmap(bmpScore, (_100 - 3) * frameW, 5, paint);
//        canvas.restore();
//        //画千位数
//        canvas.save();
//        canvas.clipRect(GameView.screenW - frameW * 4, 5, GameView.screenW - frameW * 3, 5 + framwH);
//        canvas.drawBitmap(bmpScore, (_1000 - 4) * frameW, 5, paint);
//        canvas.restore();
//        //画万位数
//        canvas.save();
//        canvas.clipRect(GameView.screenW - frameW * 5, 5, GameView.screenW - frameW * 4, 5 + framwH);
//        canvas.drawBitmap(bmpScore, (_10000 - 5) * frameW, 5, paint);
//        canvas.restore();
    }

    public void logic() {
        score[0] = (totleScore - (totleScore % 10000)) / 10000;
        score[1] = (totleScore % 10000 - totleScore % 1000) / 1000;
        score[2] = (totleScore % 1000 - totleScore % 100) / 100;
        score[3] = (totleScore % 100 - totleScore % 10) / 10;
        score[4] = totleScore % 10;
    }
}
